const CopyWebpackPlugin = require("copy-webpack-plugin")
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const common = require("./webpack.common")
const { merge } = require("webpack-merge")
const TerserWebpackPlugin = require("terser-webpack-plugin")
const OptimizeCssAssetsWebpackPlugin = require("optimize-css-assets-webpack-plugin")

module.exports = merge(common, {
    mode: "production",
    devtool: "nosources-source-map",
    optimization: {
        minimizer: [
            new TerserWebpackPlugin(),
            new OptimizeCssAssetsWebpackPlugin()
        ],
        splitChunks: {
            chunks: "all" // 标识将所有公共模块提取出来
        }
    },
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                "public"
            ]
        })
    ]
})